package com.wwwarehouse.usercenter.fragment.share;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.tools.AnimationUtils;
import com.wwwarehouse.common.tools.ConvertUtils;
import com.wwwarehouse.common.tools.QRCodeUtils;
import com.wwwarehouse.usercenter.R;
import com.wwwarehouse.usercenter.constant.UserCenterConstant;


/**
 * author ：minifly
 * date: 2017/8/31
 * time: 10:44
 * desc: 二维码分享页面 PATH_SHARE_QRCODE_OWN
 */

@Route(path = UserCenterConstant.PATH_SHARE_QRCODE_OWN)
public class ShareQRcodeFragment extends BaseFragment {
    private View mView;
    private ImageView mImgShareFragmentqrcode;
    private TextView mTvShareContent;
    private RelativeLayout mainRel,backRel;
    private LinearLayout frontLin;
    String msg = "";

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_share_qrcode_share, container, false);
        msg = getArguments().getString("ShareMsg");
        initView(mView);
        return mView;
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof ShareQRcodeFragment) {
            mActivity.setTitle(mActivity.getResources().getString(R.string.share_qrcode_share));
        }
    }

    @Override
    public void requestDatas() {

    }

    private void initView(View mView) {
        mImgShareFragmentqrcode = (ImageView) mView.findViewById(R.id.img_share_fragmentqrcode);
        mTvShareContent = (TextView) mView.findViewById(R.id.tv_share_content);
        mainRel = (RelativeLayout)mView.findViewById(R.id.share_qrcode_rel);
        frontLin = (LinearLayout) mView.findViewById(R.id.share_qrcode_front_lin);
        backRel = (RelativeLayout) mView.findViewById(R.id.share_qrcode_back_layout);

        mImgShareFragmentqrcode.setImageBitmap(QRCodeUtils.createQRCode(msg, ConvertUtils.dip2px(getActivity(),315),ConvertUtils.dip2px(getActivity(),315)));

        ImageView mIvTrans = (ImageView) mView.findViewById(R.id.iv_trans);//点击触发翻转的图标
        mIvTrans.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AnimationUtils.cardTransAnims(mainRel,frontLin,backRel,null);
            }
        });
    }
}
